var valid_number_reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
var remain_time = 60;
$(document).ready(function(){

    $("#submit").click(function(){
        var params = getInputParam("form");
        for (var k in params) {
            if (!params[k]) {
                return notify("请正确填写转出信息");
            }
        }
        console.log("params", params)
        if (!valid_number_reg.test(params.number)) {
             return notify("请正确填写转出数量");
        }
       
       transfer(params);
    });
	//冻结转流通
    $("#icetolife").click(function(){
        var params = getInputParam("form");
        for (var k in params) {
            if (!params[k]) {
                return notify("请正确填写转出信息");
            }
        }
        console.log("params", params)
        if (!valid_number_reg.test(params.number)) {
            return notify("请正确填写转出数量");
        }

        icetolife(params);
    });
    //流通转冻结
    $("#lifetoice").click(function(){
        var params = getInputParam("form");
        for (var k in params) {
            if (!params[k]) {
                return notify("请正确填写转出信息");
            }
        }
        console.log("params", params)
        if (!valid_number_reg.test(params.number)) {
            return notify("请正确填写转出数量");
        }

        lifetoice(params);
    });
	$("#vcode").click(function() {
        var param = getInputParam('form');
        if (remain_time !== 60) {
            return notify(remain_time + '秒后重新获取');
        }
        if (!param['number']) {
            return notify("请输入数量");
        }

         getSmsCode(param);
         //remain_time -= 1;

    });
});

//转出生命树
function transfer(data) {
    loading(1)
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Info/zrsms/" ,//url
        data: data,
        success: function (result) {
            if (result.code == 0) {
                loading(0)
                notify('转让成功');
                window.location.href='/index.php/Home/info/myziliao/';
            }else{
                loading(0)
                notify(result.msg);
            }
        },
        error : function() {
            loading(0)
            notify("异常！");
        }
    });
}

//冻结转流通
function icetolife(data) {
    loading(1)
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Info/icetolife/" ,//url
        data: data,
        success: function (result) {
            if (result.code == 0) {
                loading(0)
                notify('转出成功');
                window.location.href='/index.php/Home/info/myziliao/';
            }else{
                loading(0)
                notify(result.msg);
            }
        },
        error : function() {
            loading(0)
            notify("异常！");
        }
    });
}
//流通转冻结
function lifetoice(data) {
    loading(1)
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Info/lifetoice/" ,//url
        data: data,
        success: function (result) {
            if (result.code == 0) {
                loading(0)
                notify('转出成功');
                window.location.href='/index.php/Home/info/myziliao/';
            }else{
                loading(0)
                notify(result.msg);
            }
        },
        error : function() {
            loading(0)
            notify("异常！");
        }
    });
}
function getSmsCode(ob) {
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Ajax/yzm" ,//url
        data: {mobile:ob.account,number:ob.number},
        success: function (result) {
            notify("发送成功");
			changeRemainTime();
        },
        error : function() {
            notify("异常！");
            changeRemainTime();
        }
    })
}

function changeRemainTime() {

    sms_timer = setInterval(function() {
        remain_time--;
        if (!remain_time) {
            clearInterval(sms_timer);
             remain_time=60;
        }
        if(remain_time==60){
            $("#vcode").html('重新获取');
        }else{
           $("#vcode").html(remain_time + '秒'); 
        }
        
     }, 1000)
}